    namespace UnitTests.Foundation
{
    using System;
    using System.Collections.Specialized;
    using System.Web;
    using System.Web.Security;

    /// <summary>
    /// Encapsulated behaviors for use in tests.
    /// Each behavior should be static, and should be consideren closed for modification (unless the build breaks).
    /// </summary>
    public static class WebScenarios
    {
        public static void ValidFormsAuthentication(WebTestContext context)
        {
            var formsAuthCookie = new HttpCookie("formsAuthCookieName");
            var ticket = new FormsAuthenticationTicket(1, "Test", DateTime.Now.AddMinutes(-10), DateTime.Now.AddMinutes(20), false, "userData");
            formsAuthCookie.Value = FormsAuthentication.Encrypt(ticket);
            context.RequestMock.Object.Cookies.Add(formsAuthCookie);
        }

        public static void ExpiredFormsAuthentication(WebTestContext context)
        {
            var formsAuthCookie = new HttpCookie("formsAuthCookieName");
            var ticket = new FormsAuthenticationTicket(1, "Test", DateTime.Now.AddMinutes(-30), DateTime.Now.AddMinutes(-1), false, "userData");
            formsAuthCookie.Value = FormsAuthentication.Encrypt(ticket);
            context.RequestMock.Object.Cookies.Add(formsAuthCookie);
        }

        public static void HttpPost(WebTestContext context)
        {
            context.RequestMock.SetupGet(mock => mock.HttpMethod).Returns("POST");
        }

        public static void HttpGet(WebTestContext context)
        {
            context.RequestMock.SetupGet(mock => mock.HttpMethod).Returns("GET");
        }

        public static void RequestFormWith(WebTestContext context, string key, string value)
        {
            context.RequestMock.Object.Form.Add(key, value);
        }

        public static void RequestPathIs(WebTestContext context, string path)
        {
            context.RequestMock.SetupGet(mock => mock.Path).Returns(path);
        }
    }
}
